package com.chart.chart.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chart.chart.domian.SysCreenTemplate;
import com.chart.chart.domian.vo.SysCreenTemplateVO;
import com.chart.chart.service.ISysCreenTemplateService;
import com.chart.system.mapper.SysCreenTemplateMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Service
public class ISysCreenTemplateServiceImpl extends ServiceImpl<SysCreenTemplateMapper, SysCreenTemplate> implements ISysCreenTemplateService {

    @Autowired
    private SysCreenTemplateMapper sysCreenTemplateMapper;



    @Override
    public List<SysCreenTemplateVO> listCreenTemplate() {
        // 创建 LambdaQueryWrapper，并根据 sort 字段升序排序
        LambdaQueryWrapper<SysCreenTemplate> wrapper = new LambdaQueryWrapper<>();
        wrapper.orderByAsc(SysCreenTemplate::getSort); // 按 sort 字段升序排序
        wrapper.eq(SysCreenTemplate::getStatus,0);
        // 查询数据库，获取数据
        List<SysCreenTemplate> sysCreenTemplates = sysCreenTemplateMapper.selectList(wrapper);
        // 校验查询结果是否为空
        if (sysCreenTemplates == null || sysCreenTemplates.isEmpty()) {
            log.warn("查询结果为空");
            return Collections.emptyList();
        }

        ArrayList<SysCreenTemplateVO> sysCreenTemplateVOS = new ArrayList<>();

        //遍历每一个然后塞进去
        for (SysCreenTemplate sysCreenTemplate : sysCreenTemplates) {
            SysCreenTemplateVO sysCreenTemplateVO = new SysCreenTemplateVO();
            BeanUtils.copyProperties(sysCreenTemplate,sysCreenTemplateVO);
            sysCreenTemplateVOS.add(sysCreenTemplateVO);

        }

        return sysCreenTemplateVOS;
    }


}
